import 'package:mock_douban/model/home/home_requests_model.dart';

import '../http_request.dart';

final http=HttpRequest.getInstance();


class HomeDrinkRequest {
  // 获取鸡尾酒搜索结果
  static void requestDrinkList(String s) async {
    // s=margarita
    final drinkUrl = "/api/json/v1/1/search.php?s=$s";

    try {
      // 发送网络请求
      final results = await http.get<Map<String, dynamic>>(drinkUrl);
      print("results:\n${results["drinks"][0]}");
    } on Exception catch (e) {
      print("请求失败: $e");
    }
  }
}

class HomeBilibiliHotSearch{
  // https://v.api.aa1.cn/api/bilibili-rs/
  static Future<List<HomeBilibiliHotSearchModel>> requestBilibiliHotSearchList() async {
    // s=margarita
    final drinkUrl = "/api/bilibili-rs/";

    try {
      // 发送网络请求
      final response = await http.get<Map<String, dynamic>>(drinkUrl);

      // 解析 JSON 数据
      final data = response['data'] as List<dynamic>;
      final models = data.map((item) => HomeBilibiliHotSearchModel.fromJson(item as Map<String, dynamic>)).toList();
      //
      // // 打印结果
      // print("Number of items: ${models.length}");
      // print("First item: ${models[0].heat}");

      return models;
    } on Exception catch (e) {
      print("请求失败: $e");
      throw e; // 可以选择抛出异常或返回空列表
    }
  }
}